package gameheart.client.sprite;

import gameheart.server.ServerCard;
import java.awt.image.BufferedImage;

public class CardSprite extends Sprite {

    private MoveState _moveState;
    public ServerCard _content;
    public  int _destX;
    public  int _destY;
    public  int _srcX;
    public  int _srcY;
    private int _speed = 15;
    private double _a;
    private double _b;
    private double _c;
        

    public CardSprite(int x, int y, ServerCard content, ImageResposity imageResposity) {


        String fileName = "skin1/bg.jpg";
        if (content != null) {
            fileName = "skin1/"+content.getType().toString()+"_" + content.getDiem() + ".jpg";
        }
        _content = content;
        BufferedImage image = imageResposity.getImage(fileName);
        _srcX = x;
        _srcY = y;
        _destX = x;
        _destY = y;
        _moveState = new NoneMoveState();
        Init(x, y, 100, 100, image);
    }

    public void move(int x, int y) {
        _destX = x;
        _destY = y;
        _srcX = _x;
        _srcY = _y;
        _a = _srcY - _destY;
        _b = -(_srcX - _destX);
        _c = (_srcX * _destY - _srcY * _destX);
        if(_b != 0)
        {
            if(Math.abs(-_a/_b) < 1)
            {
                _moveState = new HorizonalMoveState();
            }else
            {
                _moveState = new VerticalMoveState();
            }
        }else
        {
            _moveState = new VerticalMoveState();
        }
    }

    public boolean isMoving() {
        return _moveState.isMoving(this, _a, _b, _c);
    }

    public void updatePosition() {
        _moveState.updatePosition(this, _a, _b, _c, _speed);
    }

}